package com.kitchen.ui.controls.start
{
	import com.kitchen.KitchenEvent;
	import com.kitchen.model.Vo.AccountVo;
	
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	public class StartBar extends Sprite
	{
		private var mainSkin:BitmapData;
		public var w:Number;
		public var h:Number;
		private var tf:TextField;
		public var state:Boolean;
		private var tip:StartTip;
		private var startButton:StartButton;
		private var busyButton:BusyButton = null;
		
		public function StartBar(mainSkin:BitmapData)
		{
			super();
			this.w = 150;
			this.h = 60;
			this.mainSkin = mainSkin;
			this.state = false;
			this.layout();
		}
		
		private function layout():void{
			var startBg:StartBg = new StartBg(this.mainSkin);
			this.addChild(startBg);
			startButton = new StartButton(this.mainSkin);
			startButton.x = 75;
			startButton.addEventListener(MouseEvent.CLICK, clickHandle);
			this.addChild(startButton);
			this.tf = new TextField();
			this.tf.text = '0';
			this.tf.y = 29;
			this.tf.x = 3;
			this.tf.width = 30;
			this.tf.selectable = false;
			var tff:TextFormat = new TextFormat();
			tff.font = '黑体';
			tff.size = 16;
			tff.color = 0xe44237;
			tff.bold = true;
			tff.align = TextFormatAlign.CENTER;
			this.tf.defaultTextFormat = tff;
			this.tf.filters = [new GlowFilter(0xfffefc, 1, 5, 5, 4)];
			this.addChild(this.tf);
			
			this.tip = new StartTip(this.mainSkin);
			this.tip.y = -this.h+10;
			this.addChild(this.tip);
		}
		
		public function showGuest(guest:int):void{
			this.tf.text = guest+'';
		}
		
		public function showTime(minute:int, second:int):void{
			this.tip.showTime(minute, second);
		}
		
		public function start():void{
			this.startButton.visible = false;
			if(this.busyButton == null){
				this.addBusyButton();
			}
			this.busyButton.visible = true;
			if(this.tip.state == 0){
				this.tip.open();
			}
		}
		
		public function stop():void{
			this.startButton.visible = true;
			this.busyButton.visible = false;
		}
		
		private function clickHandle(me:MouseEvent):void{
			this.dispatchEvent(new KitchenEvent(KitchenEvent.START));
		}
		
		//添加经营中按钮
		private function addBusyButton():void{
			this.busyButton = new BusyButton(this.mainSkin);
			this.busyButton.x = this.startButton.x;
			this.busyButton.y = this.startButton.y;
			this.addChild(this.busyButton);
		}
	}
}